const express=require("express")
const productList=[
	{
		title:"肉类",
		data:[
			{
				id:1,
				title:"鸡蛋",
				price:5,
				image:"/images/1.png",
				stock:20
			},
			{
				id:4,
				title:"丸子",
				price:5,
				image:"/images/4.png",
				stock:20
			}
		]
	},
	{
		title:"蔬菜",
		data:[
			{
				id:2,
				title:"青菜",
				price:1,
				image:"/images/2.png",
				stock:20
			},
			{
				id:3,
				title:"芹菜",
				price:2,
				image:"/images/3.png",
				stock:20
			},
		]
	}
	
]
const router=express.Router()
let urlIp=""
router.all('*',function(req,res,next){
    res.header("Access-Control-Allow-Origin","*");
    res.header("Access-Control-Allow-Methods","PUT,GET,POST,DELETE,OPTIONS");
    res.header("Access-Control-Allow-Headers","X-Requestd-With");
    res.header("Access-Control-Allow-Headers","Content-Type");
    next()
});
router.get("/get",(req,res)=>{
	const ip="http://"+(req.headers.host||"127.0.0.1:3003")
	if(urlIp!==ip){
		urlIp=ip
		productList.forEach(item=>{
			item.data.forEach(i=>{
				i.image=ip+i.image
			})
		})
	}
	res.send(productList)
})
router.get("/d",(req,res)=>{
	res.download("123")
})
module.exports=router